package cn.adelyn.base.auth.controller;

import cn.adelyn.base.auth.pojo.dto.RefreshTokenDTO;
import cn.adelyn.base.auth.pojo.vo.TokenInfoVO;
import cn.adelyn.base.auth.service.TokenService;
import cn.adelyn.common.core.response.ServerResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.constraints.NotBlank;

/**
 * @author chengze
 * @date 2022/12/21
 * @desc token接口
 */
@RestController
@RequestMapping("/token")
public class TokenController {

	@Autowired
	private TokenService tokenService;

	@PostMapping("/refresh")
	public ServerResponseEntity<TokenInfoVO> refreshToken(@Validated @RequestBody RefreshTokenDTO refreshTokenDTO) {
		TokenInfoVO tokenInfoVO = tokenService.freshTokenPair(refreshTokenDTO.getRefreshToken());
		return ServerResponseEntity.success(tokenInfoVO);
	}

}
